package init

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
	"service/basic/config"
)

func InitsMysql() {
	var err error
	mysqlCong := config.AppCong.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		mysqlCong.User,
		mysqlCong.Password,
		mysqlCong.Host,
		mysqlCong.Port,
		mysqlCong.Database)
	config.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	log.Println("mysql init success")
}
